package com.wangtianxiang.sxp.common.http;

import com.fasterxml.jackson.annotation.JsonValue;


public enum BizCode {
	/**
	 * SUCCESS 000: 成功
	 */
	SUCCESS("000","成功","成功"),
	/**
	 * MAINTANCE 001: 系统升级维护中
	 */
	MAINTANCE("001","系统升级维护中","系统升级维护中"),
	/**
	 * SERVICE_ERROR 002: 接口异常
	 */
	SERVICE_ERROR("002","接口异常","接口异常"),
	/**
	 * AUTH_ERROR 003: 接口鉴权失败
	 */
	AUTH_ERROR("003","接口鉴权失败","接口鉴权失败"),
	/**
	 * PARAM_CHECK_ERROR 004: 参数校验错误
	 */
	PARAM_CHECK_ERROR("004","参数校验错误","参数校验错误"),
	/**
	 * DUPLICATE 005: 重复请求
	 */
	DUPLICATE("005","重复请求","重复请求"),
	/**
	 * TOO_MANY_REQUESTS 006: 请求次数太多
	 */
	TOO_MANY_REQUESTS("006","请求次数太多","请求次数太多"),
	/**
	 * DOWNSTREAM_ERROR 100: 下游应用异常(101~199 预留为下游特定应用使用)
	 */
	DOWNSTREAM_ERROR("100","下游应用异常","下游应用异常"),

	//the code below mainly for biz
	/**
	 * NOT_LOGIN 2031: 尚未登陆
	 */
	NOT_LOGIN("2031","请先登录！","请先登录！"),
	/**
	 * PERMISSION_ERROR 4031: 用户权限校验不通过
	 */
	PERMISSION_ERROR("4031","用户权限校验不通过","用户权限校验不通过"),
	/**
	 * DATA_ERROR 4041: 数据访问失败
	 */
	DATA_ERROR("4041","数据访问失败","数据访问失败"),
	/**
	 * USER_NOT_EXIST 4042: 用户不存在
	 */
	USER_NOT_EXIST("4042","用户不存在","用户不存在"),
	/**
	 * LOGIN_UNAVAILABLE 4101: 登录失效
	 */
	LOGIN_UNAVAILABLE("4101","登录失效","登录失效"),
	/**
	 * ACCOUNT_LOCKED 4231: 账户已锁定
	 */
	ACCOUNT_LOCKED("4231","账户已锁定","账户已锁定"),
	/**
	 * THIRD_ACCOUNT_EXPIRE 4004: 账号已锁定
	 */
	THIRD_ACCOUNT_EXPIRE("4004","账号已锁定,请联系管理员","账号已锁定,请联系管理员"),

	/**
	 * THIRD_ACCOUNT_NOT_EXSITS 4006: 账号不存在或已失效
	 */
	THIRD_ACCOUNT_NOT_EXSITS("4006","账号不存在或已失效,请联系管理员","账号不存在或已失效,请联系管理员"),
	;
	private final String value;
	private final String msg;
	private final String detail;

	BizCode(String value, String msg, String detail) {
		this.value = value;
		this.msg = msg;
		this.detail = detail;
	}
	
	@JsonValue
	public String value() {
		return this.value;
	}
	
	public String getMsg() {
		return this.msg;
	}

	
	public String getDetail() {
		return detail;
	}

	/**
	 * 获取枚举对象
	 * @param statusCode
	 * @return
	 */
	public static BizCode valueOfCode(String code) {
		BizCode bizCode = resolve(code);
		if (bizCode == null) {
			throw new IllegalArgumentException("No matching constant for [" + code + "]");
		}
		return bizCode;
	}
	public static BizCode resolve(String code) {
		for (BizCode bizCode : values()) {
			if (bizCode.value.equals(code)) {
				return bizCode;
			}
		}
		return null;
	}
}
